package org.midy.infrastructure.tools;

import org.midy.infrastructure.config.SysConfig;

import java.util.concurrent.atomic.AtomicLong;

public class Logger {
    private static boolean debug = true;

    private static final AtomicLong lineCounter = new AtomicLong();

    private static final String INFO_TYPE_INFO = "INFO";
    private static final String INFO_TYPE_WARN = "WARN";
    private static final String INFO_TYPE_DEBUG = "DEBUG";
    private static final String INFO_TYPE_ERROR= "ERROR";
/*
 // 红色
 System.out.println("\033[31m这是红色的文本\033[0m");
 // 绿色
 System.out.println("\033[32m这是绿色的文本\033[0m");
 // 黄色
 System.out.println("\033[33m这是黄色的文本\033[0m");
 // 蓝色
 System.out.println("\033[34m这是蓝色的文本\033[0m");
 // 紫色
 System.out.println("\033[35m这是紫色的文本\033[0m");
 // 青色
 System.out.println("\033[36m这是青色的文本\033[0m");
 // 白色
 System.out.println("\033[37m这是白色的文本\033[0m")
 */
    private static void printMsg(String msg, String infoType) {
        if(SysConfig.printDevLog) {
            String printMsg = String.format("%s - [%s]-[%s]- %s", LocalDateFormatTool.getNowDateTimeString1(), Thread.currentThread().getName(), infoType, msg);
            System.out.println("\033[34m" + printMsg + "\033[0m");
        }
    }

    private static void printMessage(String msg) {
        String printMsg = String.format(" %s | %s", LocalDateFormatTool.getNowDateTimeString5(), msg);
        System.out.println(printMsg);
    }
    public static void info(String msg) {
        Logger.printMsg(msg, INFO_TYPE_INFO);
    }

    public static void message(String msg) {
        Logger.printMessage(msg);
    }

    public static void info(String msg, Object... params) {
        info(String.format(msg, params));
    }

    public static void warn(String msg) {
        printMsg(msg, INFO_TYPE_WARN);
    }

    public static void error(String msg, Throwable t) {
        printMsg(msg, INFO_TYPE_ERROR);
        if( t != null) {
            t.printStackTrace();
        }
    }

    public static void warn(String msg, Object... params) {
        warn(String.format(msg, params));
    }

    public static void debug(String msg) {
        if(debug) {
            printMsg(msg, INFO_TYPE_DEBUG);
        }
    }

    public static void  debug(String msg, Object... params) {
        if(debug) {
            printMsg(String.format(msg, params), INFO_TYPE_DEBUG);
        }
    }

}
